package e.odbo.data.sample.log;


import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import e.odbo.data.dao.EntityManager;
import e.odbo.data.dao.table.I_TableSentenceBuilder;
import e.odbo.data.dao.table.TableDefinition;
import e.odbo.data.dao.table.Field;
import e.odbo.data.format.Formats;
import e.odbo.data.dao.BaseDAO;


public class AppLoggerDAO extends BaseDAO<AppLogger> {

    public AppLoggerDAO(EntityManager entityManager) {
        super(entityManager);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "APP_LOGER",
                new Field[]{
                        new Field("ID",Datas.STRING,Formats.STRING),
                        new Field("USERID",Datas.STRING,Formats.STRING),
                        new Field("HOSTNAME",Datas.STRING,Formats.STRING),
                        new Field("CURDATE",Datas.TIMESTAMP,Formats.TIMESTAMP),
                        new Field("LOGTYPE",Datas.INT,Formats.INT),
                        new Field("CHANGEVALUE",Datas.STRING,Formats.STRING),
                        new Field("OBJCLASS",Datas.STRING,Formats.STRING),
                        new Field("OBJID",Datas.STRING,Formats.STRING)
                },
                new int[]{0});
    }

    @Override
    public AppLogger readValues(DataRead dr, AppLogger obj) throws BasicException {
        if(obj==null)
            obj=new AppLogger();
        obj.setId(dr.getString(1));
        obj.setUserId(dr.getString(2));
        obj.setHostName(dr.getString(3));
        obj.setCreateDate(dr.getTimestamp(4));
        obj.setType(dr.getInt(5));
        obj.setChangeValue(dr.getString(6));
        obj.setObjClass(dr.getString(7));
        obj.setObjId(dr.getString(8));
        return obj;
    }

    @Override
    public void writeInsertValues(DataWrite dp, AppLogger obj)
            throws BasicException {
        dp.setString(1,obj.getId());
        dp.setString(2,obj.getUserId());
        dp.setString(3, obj.getHostName());
        dp.setTimestamp(4,obj.getCreateDate());
        dp.setInt(5,obj.getType());
        dp.setString(6,obj.getChangeValue());
        dp.setString(7,obj.getObjClass());
        dp.setString(8,obj.getObjId());
    }

    @Override
    public Class getSuportClass() {
        return AppLogger.class;
    }
}
